<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition >

        <p:panel id="addresspanel" header="Shipping Requests">
            <h:panelGroup >
                <p:dataTable id="addresslist" value="#{shippingRequestEntityController.shippingRequests}" 
                             var="shippingrequest" paginator="false" widgetVar="addresstable" > 

                    <p:column >  
                        <h:outputText value="Address: #{shippingrequest.address.address}" />
                        <br />

                        <h:outputText value="#{shippingrequest.product}: " />
                        <h:outputText value="#{shippingrequest.quantity}" /> 
                        <br />
                        <h:outputText value="Shipping Date: #{shippingrequest.shippingDate}" rendered="#{shippingrequest.shippingDate!=null}">
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputText>
                    </p:column>

                    <p:column>
                        <p:commandButton value="Edit" action="#{shippingRequestEntityController.removeFromPurchaseOrder}" 
                                         oncomplete="shippingDialog.show()" update="@form:displayRequest" 
                                         process="@form:addresspanel">
                            <f:setPropertyActionListener value="#{shippingrequest}"  
                                                         target="#{shippingRequestEntityController.current}" /> 
                        </p:commandButton>
                    </p:column>

                    <p:column >  
                        <p:commandButton value="Delete" action="#{shippingRequestEntityController.destroy}" 
                                         update="@form:addresspanel" process="@form:addresspanel">  
                            <f:setPropertyActionListener value="#{shippingrequest}" 
                                                         target="#{shippingRequestEntityController.current}" />  
                        </p:commandButton>  
                    </p:column>
                </p:dataTable>
                <br />
                <p:commandLink value="Add Shipping Request" action="#{shippingRequestEntityController.recreateModel}" update="displayRequest" 
                               onsuccess="shippingDialog.show();" process="@parent"/>

                <p:dialog header="Edit Shipping Request" widgetVar="shippingDialog" resizable="false"  
                          width="600" showEffect="explode" hideEffect="explode">  

                    <h:panelGrid id="displayRequest" columns="2" >

                        <h:outputLabel value="Shipping Address:" />
                        <h:selectOneMenu id="shippingAddress" value="#{shippingRequestEntityController.selected.address}" converter="addressConverter" >
                            <f:selectItems value="#{addressEntityController.shippingAddressesAvailableSelectOne}"/>
                        </h:selectOneMenu>

                        <h:outputLabel value="Product:" />
                        <h:selectOneMenu id="product" value="#{shippingRequestEntityController.selected.product}" converter="productConverter">
                            <f:selectItems value="#{completedGoodsEntityController.itemsAvailableSelectOne}"/>
                        </h:selectOneMenu>
                        
                        <h:outputLabel value="Shipping Date: " rendered="#{purchaseOrderEntityController.selected.id!=null}"/>
                        <p:calendar value="#{shippingRequestEntityController.selected.shippingDate}" mindate="#{purchaseOrderEntityController.getToday()}" rendered="#{purchaseOrderEntityController.selected.id!=null}"/>
                        
                        <h:outputLabel value="Quantity: " />
                        <h:inputText value="#{shippingRequestEntityController.selected.quantity}" />                

                        <h:outputText value=" " />
                        <p:commandButton action="#{shippingRequestEntityController.updateOrEditWithoutRedirect}" value="Save" update="addresslist" oncomplete="shippingDialog.hide();" process="@parent"/>
                    </h:panelGrid>

                </p:dialog> 

            </h:panelGroup>
        </p:panel>
    </ui:composition>

</html>
